$(document).ready(function () {

    // BOOTSTRAP TABLES USING FONT AWESOME ICONS
    // =================================================================
    // Require Bootstrap Table
    // http://bootstrap-table.wenzhixin.net.cn/
    //
    // =================================================================
    jQuery.fn.bootstrapTable.defaults.icons = {
        paginationSwitchDown: 'demo-pli-arrow-down',
        paginationSwitchUp: 'demo-pli-arrow-up',
        refresh: 'demo-pli-repeat-2',
        toggle: 'demo-pli-layout-grid',
        columns: 'demo-pli-check',
        detailOpen: 'demo-psi-add',
        detailClose: 'demo-psi-remove'
    }

    // EDITABLE - COMBINATION WITH X-EDITABLE
    // =================================================================
    // Require X-editable
    // http://vitalets.github.io/x-editable/
    //
    // Require Bootstrap Table
    // http://bootstrap-table.wenzhixin.net.cn/
    //
    // Require X-editable Extension of Bootstrap Table
    // http://bootstrap-table.wenzhixin.net.cn/
    // =================================================================
    $('#event-editable').bootstrapTable({
        idField: 'id',
        method: 'PUT',
        url: '/event/read/list',
        columns: [
            {
                field: 'id',
                title: 'ID'
            }, {
                field: 'userName',
                title: '用户名',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'title',
                title: '操作'
            }, {
                field: 'userName',
                title: '清理人',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'createTime',
                title: '操作时间',
            }, {
                field: 'clientHost',
                title: 'IP',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'userAgent',
                title: '浏览器',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'remark',
                title: '备注',
                editable: {
                    type: 'text'
                }
            }]
    });

    $('#scheduled-editable').bootstrapTable({
        idField: 'id',
        method: 'PUT',
        url: '/scheduled/read/log',
        columns: [
            {
                field: 'id',
                title: 'ID'
            }, {
                field: 'groupName',
                title: '任务组',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'taskName',
                title: '任务名称'
            }, {
                field: 'startTime',
                title: '开始时间',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'endTime',
                title: '结束时间',
            }, {
                field: 'serverHost',
                title: '服务器',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'status',
                title: '状态',
                editable: {
                    type: 'text'
                }
            }, {
                field: 'remark',
                title: '备注',
                editable: {
                    type: 'text'
                }
            }]
    });
});


// FORMAT COLUMN
// Use "data-formatter" on HTML to format the display of bootstrap table column.
// =================================================================


// Sample format for Invoice Column.
// =================================================================
function invoiceFormatter(value, row) {
    return '<a href="#" class="btn-link" > Order #' + value + '</a>';
}


// Sample Format for User Name Column.
// =================================================================
function nameFormatter(value, row) {
    return '<a href="#" class="btn-link" > ' + value + '</a>';
}


// Sample Format for Order Date Column.
// =================================================================
function dateFormatter(value, row) {
    var icon = row.id % 2 === 0 ? 'fa-star' : 'fa-user';
    return '<span class="text-muted"><i class="fa fa-clock-o"></i> ' + value + '</span>';
}


// Sample Format for Order Status Column.
// =================================================================
function statusFormatter(value, row) {
    var labelColor;
    if (value == "Paid") {
        labelColor = "success";
    } else if (value == "Unpaid") {
        labelColor = "warning";
    } else if (value == "Shipped") {
        labelColor = "info";
    } else if (value == "Refunded") {
        labelColor = "danger";
    }
    var icon = row.id % 2 === 0 ? 'fa-star' : 'fa-user';
    return '<div class="label label-table label-' + labelColor + '"> ' + value + '</div>';
}


// Sample Format for Tracking Number Column.
// =================================================================
function trackFormatter(value, row) {
    if (value) return '<i class="fa fa-plane"></i> ' + value;
}


// Sort Price Column
// =================================================================
function priceSorter(a, b) {
    a = +a.substring(1); // remove $
    b = +b.substring(1);
    if (a > b) return 1;
    if (a < b) return -1;
    return 0;
}